
function setSlider(el,options){
    var defaults={
        initindex:1,
        speed:0,
        isdot:true
    }
    this.el=el;
    this.option={}

    this.option.initindex=typeof(options.initindex)!=='undefined'?options.initindex:defaults.initindex;
    this.option.speed=typeof(options.speed)!=='undefined'?options.speed:defaults.speed;
    this.option.isdot=typeof(options.isdot)!=='undefined'?options.isdot:defaults.isdot;
    this.slide_list=el.querySelector('.slide-list');
    this.items=this.slide_list.querySelectorAll('#slide-item');
    this.index=this.getcurindex(this.option.initindex);
    this.distance=this.items[0].offsetWidth;
    var self=this
    this.slide_list.ontransitionend=function(){
        //
    this.slide_list.style.transitionDuration=0+'ms';
    if(typeof cb==='function'){
        cb();
    }
    }
    if( this.option.isdot){
    this.dot_list=document.createElement('ul');
    var html=''
    for(var i=0; i<this.items.length;i++){
        html+='<li id="dot-item"></li>';
    }
    this.dot_list.innerHTML+=html;
    this.dot_list.id='dot-list';
    el.appendChild(this.dot_list);
    this.move(this.setdistancebyindex(this.index))

}
this.setbot()
}
setSlider.prototype.to=function(index,speed,cb){  

    this.index=index;
    this.index=this.getcurindex(this.index);
    this.setbot()
    this.slide_list.style.transitionDuration=speed+'ms';
    this.move(this.setdistancebyindex(this.index))
}
setSlider.prototype.prve=function(cb){
    this.index--
    this.index=this.getcurindex(this.index);
    this.setbot()
    this.to(this.index,this.option.speed,cb)

}
setSlider.prototype.next=function(cb){

    this.index++
    this.index=this.getcurindex(this.index);
    this.setbot()
    this.to(this.index,this.option.speed,cb)

}
setSlider.prototype.setdistancebyindex=function(index){
        this.index=index;
       this.setdistance=this.index*this.distance;
       return   this.setdistance;
 }
setSlider.prototype.move=function(distance){
    this.slide_list.style.transform='translate3d('+-distance+'px,0,0)';
}
setSlider.prototype.getcurindex=function(index){
    if(index>this.items.length-1){
        index=0;
    }else if(index<0){
        index=this.items.length-1;
    }
    return index;
}
setSlider.prototype.setbot=function(){
    this.dots=this.dot_list.querySelectorAll('#dot-item');
    for(var i=0;i<this.dots.length;i++){
        this.dots[i].className=''
    }
    this.dots[this.index].className='cur'
}
